from django.db import models


class MenuBarItems(models.Model):
    menu_bar_name = models.CharField(max_length=50, default='', unique=True, verbose_name='名称')
    menu_bar_order = models.IntegerField(default=0, verbose_name='排序')
    menu_bar_url = models.CharField(max_length=200, default='', unique=True, verbose_name='链接地址')
    menu_bar_icon = models.CharField(max_length=255, default='', verbose_name='图标地址')
    menu_bar_class_id = models.IntegerField(default=0, verbose_name='分类表id')
    need_login = models.IntegerField(default=0, verbose_name='是否需要登录')

    def to_json(self, not_show=None):
        if not_show is None:
            return {attr: getattr(self, attr) for attr in [f.name for f in self._meta.fields]}
        else:
            return {attr: getattr(self, attr) for attr in [f.name for f in self._meta.fields if f.name not in not_show]}

    class Meta:
        db_table = 'menu_bar_items'


class MenuBarClass(models.Model):
    menu_bar_class_name = models.CharField(max_length=50, default='', unique=True, verbose_name='分类名称')
    menu_bar_class_order = models.IntegerField(default=0, verbose_name='排序')
    menu_bar_class_icon = models.CharField(max_length=255, default='', verbose_name='图标地址')

    def to_json(self, not_show=None):
        if not_show is None:
            return {attr: getattr(self, attr) for attr in [f.name for f in self._meta.fields]}
        else:
            return {attr: getattr(self, attr) for attr in [f.name for f in self._meta.fields if f.name not in not_show]}

    class Meta:
        db_table = 'menu_bar_class'
